package top.xia17.plugins.fast.common.spring.converter;

import cn.hutool.core.util.StrUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;

/**
 * 字符串转 Boolean
 * @author xia17
 * @date 2020/12/24 15:23
 */
public class StringToBooleanConverter  implements Converter<String, Boolean> {

    private static final String NULL_STR = "null";

    @Override
    public Boolean convert(@NonNull String s) {
        if(StrUtil.isBlank(s)){
            return null;
        }
        if (NULL_STR.equalsIgnoreCase(s)){
            return null;
        }
        return Boolean.parseBoolean(s);
    }
}
